package cn.itcast.bos.web.action;

import cn.itcast.bos.domain.take_delivery.Order;
import cn.itcast.bos.service.OrderService;
import cn.itcast.bos.web.action.common.BaseAction;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Think on 2017/9/28.
 */
@ParentPackage(value="json-default")
@Namespace("/")
@Controller
@Scope("prototype")
public class OrderAction extends BaseAction<Order> {

    @Autowired
    private OrderService orderService;

    /**使用订单号查询订单*/
    @Action(value="order_findByOrderNum",results={@Result(name="success",type="json")})
    public String findByOrderNum(){
        Map<String,Object> map = new HashMap<>();
        String orderNum = model.getOrderNum();
        //返回唯一对象
        Order order = orderService.findByOrderNum(orderNum);
        //没有查到数据
        if(order==null){
            map.put("success", false);
        }else{
            map.put("success", true);
            map.put("orderData", order);
        }
        ServletActionContext.getContext().getValueStack().push(map);

        return SUCCESS;
    }
}
